let db = require("../commons/db")
let JSONResponse = require("../commons/JSONResponse")

exports.listAll = (req, resp) => {
    db.query("select * from news")
        .then(res => {
            console.log("newsList", res)
            if (res) {
                resp.json(JSONResponse.success(res, 200, "获取成功"))
            }
            else resp.json(JSONResponse.fail("获取失败", 400, null))
        })
}

exports.getNewsDetail = (req, resp) => {
    let id = req.query.id
    // console.log("id", id)
    db.queryOne("select * from news where id=?", [id])
        .then(res => {
            // console.log("newsDetail", res)
            if (res) {
                resp.json(JSONResponse.success(res, 200, "获取成功"))
            }
            else resp.json(JSONResponse.fail("获取失败", 400, null))
        })
}